import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/SiteView.vue'
import MockView from '../views/MockView.vue'
import PhotoView from '../views/PhotoView.vue'
import {getToken} from "@/utils/token";
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import SystemView from "@/views/SystemView";
import TableView from "@/views/TableView";
import ConfigView from "@/views/ConfigView";
import AudioView from "@/views/AudioView";
import WallpaperView from "@/views/WallpaperView";
import IndexView from "@/views/IndexView";
import AboutView from "@/views/AboutView";
import ContactView from "@/views/ContactView";
import CalendarView from '@/views/CalendarView.vue';
import WeatherView from '@/views/WeatherView.vue'; 
import MemoView from '@/views/MemoView.vue';
import NoteView from '@/views/NoteView.vue';
import TimeConverterView from '@/views/TimeConverterView.vue';
import JsonView from '@/views/JsonView.vue';
import supportAudio from '@/views/supportAudio.vue';
import supportVideo from '@/views/supportVideo.vue';

Vue.use(VueRouter)

const routes = [
  {
    path: '/index',
    name: 'index',
    component: IndexView
  },{
    path: '/',
    name: 'home',
    component: HomeView
  },{
    path: '/wallpaper',
    name: 'wallpaper',
    component: WallpaperView
  },{
    path: '/photo',
    name: 'photo',
    component: PhotoView
  },{
    path: '/table',
    name: 'table',
    component: TableView
  },
  {
    path: '/mock',
    name: 'mock',
    component: MockView
  }, {
    path: '/system',
    name: 'system',
    component: SystemView
  },{
    path: '/config',
    name: 'config',
    component: ConfigView
  },{
    path: '/audio',
    name: 'audio',
    component: AudioView
  },
  {
    path: '/login',
    name: 'login',
    component: function () {
      return import(/* webpackChunkName: "about" */ '../views/LoginView.vue')
    }
  },{
    path: '/about',
    name: 'about',
    component: AboutView
  },{
    path: '/contact',
    name: 'contact',
    component: ContactView
  },{
    path: '/calendar',
    name: 'calendar',
    component: CalendarView
  },{
    path: '/weather',
    name: 'weather',
    component: WeatherView
  },{
    path: '/memo',
    name: 'memo',
    component: MemoView
  },
  {
    path: '/note',
    name: 'note',
    component: NoteView
  },
  {
    path: '/timeConverter',
    name: 'timeConverter',
    component: TimeConverterView
  },
  {
    path: '/jsonFormat',
    name: 'jsonFormat',
    component: JsonView
  },{
    path: '/supportAudio',
    name: 'supportAudio',
    component: supportAudio
  },
  {
    path: '/supportVideo',
    name: 'supportVideo',
    component: supportVideo
  }
]

const router = new VueRouter({
  routes
})

NProgress.configure({
  easing: 'ease',  // 动画方式，和css动画属性一样（默认：ease）
  speed: 500,  // 递增进度条的速度，单位ms（默认： 200）
})


router.beforeEach((to, from , next) => {
  //每次切换页面时，调用进度条
  //NProgress.start();
  var token = getToken();
  if(!token && to.name !== 'login'){
    next({
      name:'login'
    })
    return
  }
  // 这个一定要加，没有next()页面不会跳转的。
  next();
});
router.afterEach(() => {
  // 在即将进入新的页面组件前，关闭掉进度条
  //NProgress.done()
})

export default router
